package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.pojo.Goods;
import com.qf.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodsConreoller {
    @Autowired
    GoodsService goodsService;

    @GetMapping("/goods-list")
    public String goodsList( Integer categoryId, Model model){

        List<Goods> list=new ArrayList<>();
        List<Goods> goods = goodsService.goodsList(categoryId);
        model.addAttribute("goods", goods);
        return "goods_list";
    }

    @GetMapping("/detail")
    public String detail( Integer id, Model model){
       Goods goods= goodsService.detail(id);
       model.addAttribute("goods", goods);
       return "detail";
    }

    @GetMapping("/list")
    public String list( Integer id,@RequestParam(value = "pageNum" ,defaultValue = "1")Integer pageNum,
                       @RequestParam(value = "pageSize" ,defaultValue = "5")Integer pageSize,
                        Model model,Integer state){

        System.out.println("++++++"+state);
        PageInfo<Goods> pageInfo =goodsService.listAll(id,pageNum,pageSize,state);
//        System.out.println(pageInfo.getList());
        model.addAttribute("state", state);
        model.addAttribute("pageInfo", pageInfo);
        return "list";


    }




}
